/************************************************************************/
/* GUI                                                                  */
/************************************************************************/
#include "GUI/Bars/HealthBar.h"

namespace TD_GUI {


	/************************************************************************/
	/* Default definitions                                                  */
	/************************************************************************/
	const unsigned int HealthBar::backgroundOffset = 2; //2 pixels


	HealthBar::HealthBar() {

	}


	HealthBar::HealthBar(const HealthBar &rhs) {

	}

	HealthBar & HealthBar::operator =(const HealthBar & rhs) {
		return(*this);
	}

	HealthBar::HealthBar(const Coord2D & barPosition, const Coord2D & barSize,
      Color foregroundColor /* = Color::GREEN */, Color backgroundColor /* = Color::BLACK */) : BaseBar(barPosition, barSize, foregroundColor, backgroundColor) {

			m_foregroundRect.w = 0;
			m_currHealth = 0.0f;
	}

	HealthBar::~HealthBar() {
		
	}

	void HealthBar::update(const unsigned int deltaTime) {
		if (m_currHealth <= 1.0 && m_currHealth >= 0.0) {
			m_foregroundRect.w = (m_backgroundRect.w - backgroundOffset) * m_currHealth;
			if(m_currHealth <= 0.7 && m_currHealth >= 0.3) {
				m_foregroundColor = Color::YELLOW;
			} else if(m_currHealth <= 0.3) {
				m_foregroundColor = Color::RED;
			}
		} else if(m_currHealth < 0) {
			m_foregroundRect.w = 0;
		}
	}

	void HealthBar::render(SDL_Surface *const g_destSurface, unsigned int deltaTime) {
      BaseBar::render(g_destSurface, deltaTime);

		update(deltaTime);
		m_foregroundRect.h = m_size.y - backgroundOffset;


		SDL_FillRect(g_destSurface, &m_backgroundRect, SDL_MapRGB(g_destSurface->format, m_backgroundColor.red, m_backgroundColor.green, m_backgroundColor.blue));
		SDL_FillRect(g_destSurface, &m_foregroundRect, SDL_MapRGB(g_destSurface->format, m_foregroundColor.red, m_foregroundColor.green, m_foregroundColor.blue));

	}
}